#ifndef _TemplateAnalyzer_H_
#define _TemplateAnalyzer_H_
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <cstring>
#include <netinet/in.h>
#include <linux/types.h>
#include <linux/netfilter.h>		/* for NF_ACCEPT */
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <errno.h>


#define TCP_PRO 6

#define UDP_PRO 17
#define UDP_HEADER_LEN 8

using namespace std;
class TemplateAnalyzer{
public:
	TemplateAnalyzer(unsigned char *data,int _ret);
	virtual bool analyze_appLayer(unsigned char *data,int &startLen)=0;
	int get_tran_type();
	bool get_app_type();
	int get_app_startLen();

protected:
	int tran_type;
	bool app_type;
	int ret;
	int startLen;
private:
	void do_analyze(unsigned char *data);
	struct iphdr* analyze_ipLayer(unsigned char *data);
	int analyze_tranLayer(struct iphdr* iph,unsigned char *data);

};

TemplateAnalyzer::TemplateAnalyzer(unsigned char *data,int _ret):ret(_ret)
{
	this->tran_type=0;
	this->startLen=0;
	this->app_type=false;
	do_analyze(data);
}

void TemplateAnalyzer::do_analyze(unsigned char *data)
{
	struct iphdr* iph=analyze_ipLayer(data);
	this->tran_type=analyze_tranLayer(iph,data);
}

struct iphdr* TemplateAnalyzer:: analyze_ipLayer(unsigned char *data)
{
	struct iphdr* iph=((struct iphdr *)data);
	return iph;
}
int TemplateAnalyzer::analyze_tranLayer(struct iphdr* iph,unsigned char *data)
{
	if(iph->protocol == TCP_PRO)
		return TCP_PRO;
	else if(iph->protocol==UDP_PRO)
		return UDP_PRO;
	else 
		return 0;
}
int TemplateAnalyzer::get_tran_type()
{
	return this->tran_type;
}
bool TemplateAnalyzer::get_app_type()
{
	return this->app_type;
}
int TemplateAnalyzer::get_app_startLen()
{
	return this->startLen;
}
#endif